define(function(require, exports, module) {
	J = jQuery;
	require('knob');
	require('layer');
	layer.config({
	    path: '/assets/vendors/layer/' //layer.js所在的目录，可以是绝对目录，也可以是相对目录
	});
	require('masonry');
	var timenow = new Date().getTime();
	
	$("#user-follow").on("click", function(){
		var userid=$(this).attr("data-user-id");
		$.ajax({
    		url: '/member/userfollow.json?'+timenow, 
    		data: {'user_byid': userid},
    		dataType: "json",
    		type :  "POST",
    		cache : false,
    		async: false,
    		error : function(i, g, h) {
    			layer.msg('请登录后操作', {icon: 2});
    		},
    		success: function(data){	
    			if(data.result){
    				if(data.t.relation_type>=2){
    					layer.msg("关注成功", {icon: 1});
    					$("#user-follow").html('<i class="icon iconfont">&#xe6d3;</i>已关注').removeClass("move");
    				}else{
    					layer.msg("已取消关注", {icon: 2});
    					$("#user-follow").html('<i class="icon iconfont">&#xe636;</i> 关注').addClass("move");
    				}
    			}else{
					layer.msg(data.errors.msg, {icon: 2});
					return false;
				}
          	}
    	});
	});
	var userid=$(".followerUser").attr("data-source_id");
	if(userid>0){
		$.getJSON("/member/addVisitRecord.json",{userId:userid},function(result){
		    $.each(result, function(i, field){
		        //$("p").append(field + " ");
		    });
		});
	}
	
	
	$("#my-gallery-container").mpmansory(
			{
				childrenClass: 'item', // default is a div
				columnClasses: 'padding', //add classes to items
				breakpoints:{
					lg: 3, 
					md: 3, 
					sm: 4,
					xs: 6
				},
				distributeBy: { order: false, height: false, attr: 'data-order', attrOrder: 'asc' }, //default distribute by order, options => order: true/false, height: true/false, attr => 'data-order', attrOrder=> 'asc'/'desc'
				onload: function (items) {
					//make somthing with items
				} 
			}
		);
	
	//发送站内邮件
	$("#sendTo_submit").on("click", function(){
		var state=$("#state").val();
		var toid=$("#toid").val();
		var subject=$("#subject").val();
		var message=$("#message-text").val();
		
		$.ajax({
    		url: '/member/addmessage.json?'+timenow, 
    		data: {'state': state,'toid': toid,'subject': subject,'message': message},
    		dataType: "json",
    		type :  "POST",
    		cache : false,
    		async: false,
    		error : function(i, g, h) {
    			layer.msg('请登录后操作', {icon: 2});
    		},
    		success: function(data){	
    			if (data.code==0) {
    				layer.msg(data.message, {icon: 1});
    				$('#sendTo_message_model').modal('hide');
    				$("#subject").val("");
    				$("#message-text").val("");
    			}else{
    				layer.msg(data.message, {icon: 2});
    			}
          	}
    	});
		return false;
	});	
});